package dbs

import (
	"github.com/jinzhu/gorm"
	"time"
)

type Patient struct {
	Id           uint      `gorm:"column:id;type:int(10) unsigned;primary_key;AUTO_INCREMENT" json:"id"`
	PatientId    uint      `gorm:"column:patient_id;type:int(10) unsigned" json:"patient_id"`
	AdmissTimes  uint      `gorm:"column:admiss_times;type:int(10) unsigned" json:"admiss_times"`
	InpatientNo  string    `gorm:"column:inpatient_no;type:varchar(255)" json:"inpatient_no"`
	Name         string    `gorm:"column:name;type:varchar(255)" json:"name"`
	AdmissDate   time.Time `gorm:"column:admiss_date;type:datetime" json:"admiss_date"`
	AdmissStatus uint      `gorm:"column:admiss_status;type:int(10) unsigned" json:"admiss_status"`
	AdmissDept   string    `gorm:"column:admiss_dept;type:varchar(255)" json:"admiss_dept"`
	AdmissWard   string    `gorm:"column:admiss_ward;type:varchar(255)" json:"admiss_ward"`
	BedNo        int       `gorm:"column:bed_no;type:int(11)" json:"bed_no"`
	Sex          uint      `gorm:"column:sex;type:int(10) unsigned" json:"sex"`
	UnitSn       string    `gorm:"column:unit_sn;type:varchar(255)" json:"unit_sn"`
	Expr1        string    `gorm:"column:expr1;type:varchar(255)" json:"expr1"`
	Expr2        string    `gorm:"column:expr2;type:varchar(255)" json:"expr2"`
}

type PatientCreate struct {
	InpatientNo string    `gorm:"column:inpatient_no;type:varchar(255)" json:"inpatient_no"`
	Name        string    `gorm:"column:name;type:varchar(255)" json:"name"`
	AdmissDate  time.Time `gorm:"column:admiss_date;type:datetime" json:"admiss_date"`
	Sex         uint      `gorm:"column:sex;type:int(10) unsigned" json:"sex"`
	Expr1       string    `gorm:"column:expr1;type:varchar(255)" json:"expr1"`
	Expr2       string    `gorm:"column:expr2;type:varchar(255)" json:"expr2"`
}

func (self *PatientCreate) Create() (err error) {
	err = D_Pool(func(db **gorm.DB) (err error) {
		conn := *db

		return conn.Create(&self).Error
	})
	return
}
